
module.exports = function($scope,$http,$q, $state, $stateParams,$resource,$modal){
    $scope.searchform = {};
    $scope.maxSize = 5;             //最多显示多少个按钮
    $scope.currentPage = 1;      //当前页码
    $scope.itemsPerPage = 10         //每页显示几条
    $scope.starr=[
        {name:'请选择',value:''},
        {name:'草稿',value:'0'},
        {name:'待审核',value:'1'},
        {name:'已通过',value:'2'},
        {name:'已驳回',value:'3'},
    ]
    $scope.pageChanged = function () {
        console.log($scope.searchform.state)
        var dic = {
            pageNo:$scope.currentPage,
            pageSize:$scope.itemsPerPage,
            state:$scope.searchform.state
        }
        // console.log(dic);
        $resource('/api/as/ggc/equipmentnotice/findList', {}, {}).save(dic, function(res){
        if(res.errcode === 0 || res.errcode === 10003){
            console.log(res);
            $scope.list=res.data.results;
            $scope.totalItems = res.data.totalRecord;
            $scope.list.forEach(element => {
                if(element.state == '0'){
                    element.state_name = '草稿'
                }
                if(element.state == '1'){
                    element.state_name = '审核中'
                }
                if(element.state == '2'){
                    element.state_name = '已通过'
                }
                if(element.state == '3'){
                    element.state_name = '已驳回'
                }
            });
        }else{
            alert(res.errmsg);
        }
        });
    };
    $scope.pageChanged();

    $scope.pass=function(obj){
        $resource('/api/as/ggc/equipmentnotice/updatePass', {}, {}).save({id:obj.id}, function(res){
            if(res.errcode === 0 || res.errcode === 10003){
                alert('通过成功')
                $scope.pageChanged();
            }else{
                alert(res.errmsg);
            }
        });
    }

    $scope.reject=function(obj){
        $resource('/api/as/ggc/equipmentnotice/updateBack', {}, {}).save({id:obj.id}, function(res){
            if(res.errcode === 0 || res.errcode === 10003){
                alert('驳回成功')
                $scope.pageChanged();
            }else{
                alert(res.errmsg);
            }
        });
    }

    $scope.information=function(obj){
        $scope.item = obj;
        $scope.flag = 'information';
        var modalInstance = $modal.open({
            template: require('../views/editNotice.html'),
            controller: 'editNotice',
            size: 'lg',
            resolve: {
                items: function () {
                    return $scope.item;
                },
                flag: function () {
                    return $scope.flag;
                }
            }
        });
        modalInstance.opened.then(function () {
        });
        modalInstance.result.then(function (showResult) {
        }, function (reason) {
            // click，点击取消，则会暑促cancel
            $log.info('Modal dismissed at: ' + new Date());
        });
    }

}